"""
发送post请求，用类与对象来实现

"""

import requests


class YouDao:
    pass

    def __init__(self, inp):
        self.inp = inp

        self.url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
        self.headers = {
            'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
        }
        self.data = {
            'i': inp,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': '16070708939084',
            'sign': '385144be417195dd92916372922a67c5',
            'lts': '1607070893908',
            'bv': '02edb5d6c6ac4286cd4393133e5aab14',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME'
        }
    #翻译功能
    def translate(self):
        resp = requests.post(self.url, headers=self.headers, data=self.data)
        return resp.content.decode()


# 程序入口
if __name__ == "__main__":
    fan1 = YouDao("英文输入")
    print(fan1.translate())
